package net.ibizsys.eclipse.studio.tree;

import net.ibizsys.eclipse.studio.Activator;
import net.ibizsys.eclipse.studio.util.StringKit;

import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.swt.graphics.Image;

/**
 * 树节点文本绘制对象
 * 
 * @author <a href='http://www.weibo.com/xjtoo' target='_blank'>Enmaai</a>
 */
public class IBizTreeTextLabelProvider implements DelegatingStyledCellLabelProvider.IStyledLabelProvider
{
	@Override
	public void addListener(ILabelProviderListener listener)
	{
	}

	@Override
	public void dispose()
	{
	}

	@Override
	public boolean isLabelProperty(Object data, String info)
	{
		return false;
	}

	@Override
	public void removeListener(ILabelProviderListener listener)
	{
	}

	@Override
	public Image getImage(Object data)
	{
		if (data instanceof IBizTreeNode)
		{
			return Activator.GetImage(((IBizTreeNode) data).getIcon());
		}
		return null;
	}

	@Override
	public StyledString getStyledText(Object data)
	{
		StyledString text = new StyledString();
		if (data instanceof IBizTreeNode)
		{
			IBizTreeNode node = (IBizTreeNode) data;

			text.append(node.getText());
			if (!StringKit.IsBlank(node.getDesc()))
			{
				text.append(" ");
				text.append(node.getDesc(), StyledString.DECORATIONS_STYLER);
			}
		} else
		{
			text.append("数据类型错误.");
		}

		return text;
	}
}
